package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.view.entity.GoodsPublishSkuListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SpecPriceAdapter extends BaseRecycleAdapter<GoodsPublishSkuListEntity> {
    private TextView tv_line;
    private TextView tv_remove;
    private EditText et_price;
    private TextView tv_name;
    private LinearLayout ll_title;

    public SpecPriceAdapter(Context context, List<GoodsPublishSkuListEntity> datas) {
        super(context, R.layout.item_spec_price, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final GoodsPublishSkuListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        tv_line = holder.itemView.findViewById(R.id.tv_line);
        tv_remove = holder.itemView.findViewById(R.id.tv_remove);
        et_price = holder.itemView.findViewById(R.id.et_price);
        tv_name = holder.itemView.findViewById(R.id.tv_name);
        ll_title = holder.itemView.findViewById(R.id.ll_title);
        et_price.setText(entity.getMoney());
        if (holder.getLayoutPosition() == 0) {
            //第一条数据隐藏这条线
            tv_line.setVisibility(View.GONE);
        } else {
            tv_line.setVisibility(View.VISIBLE);
        }
        if (entity.isFill()) {
            ll_title.setVisibility(View.GONE);
        } else {
            ll_title.setVisibility(View.VISIBLE);
            String name = "";
            if (entity.getList() != null) {
                for (int i = 0; i < entity.getList().size(); i++) {
                    if (i != entity.getList().size() - 1) {
                        name = name + entity.getList().get(i).getVal() + "-";
                    } else {
                        name = name + entity.getList().get(i).getVal();
                    }
                }
            }
            tv_name.setText(name);
            tv_remove.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    datas.remove(holder.getLayoutPosition());
                    notifyDataSetChanged();
                }
            });
        }
    }
}
